using System;
using System.Security.Cryptography;
using System.Text;

namespace CoreApp.Utility
{
    public class Md5Helper
    {
        /// <summary>
        /// md5加密
        /// </summary>
        /// <param name="input">待加密的字符串</param>
        /// <param name="encodingName">编码</param>
        /// <returns></returns>
        public static string MD5Hash(string input, string encodingName="utf-8")
        {
            using (var md5 = MD5.Create())
            {
                var bytes = Encoding.GetEncoding(encodingName).GetBytes(input);
                var result = md5.ComputeHash(bytes);
                var strResult = BitConverter.ToString(result);
                return strResult.Replace("-", "");
            }
        }
    }
}